package cn.lvji.sus.maps;

import cn.lvji.sus.Maps;
import cn.lvji.sus.db.JDBCUtils;
import cn.lvji.sus.redis.RedisUtils;

/**
 * redis简单实现
 *
 * @author zhouzx
 */
public class RedisUrlMaps implements Maps {
    @Override
    public String maps(String url) {
        String cached = RedisUtils.get(url);
        if (cached == null) {
            return JDBCUtils.getLongUrl(url);
        }
        return cached;
    }

    @Override
    public void addUrl(String longUrl, String shortUrl) {
        RedisUtils.put("sus_" + shortUrl, longUrl);
    }
}
